'''
发送post请求,用类与对象的方式实现
'''
import requests


class YouDao:

    def __init__(self,word):
        self.url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
        }
        self.data = {
            'i': word,
            'from': 'AUTO',
            'to': 'AUTO',
            'smartresult': 'dict',
            'client': 'fanyideskweb',
            'salt': '16063694928764',
            'sign': '89311d19d58b552bb289908aac249622',
            'lts': '1606369492876',
            'bv': 'f7d97c24a497388db1420108e6c3537b',
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_REALTlME'
        }

    # 自定义函数,完成post请求功能
    def fan_yi(self):
        html = requests.post(self.url, headers=self.headers, data=self.data)
        print(html.content.decode())





fan1=YouDao('加油')
fan1.fan_yi()
fan2=YouDao('hello')
fan2.fan_yi()


















